﻿
@model RonYee.Models.INetMvc3Page
@if (Model.TotalPage > 0 && Model.CurrentPageIndex <= Model.TotalPage)
{

    <div id="mvcpager">         
        @if (Model.CurrentPageIndex > 1)
        {            
             <a  href="javascript:gotopage(1,@Model.TotalPage)" style="margin-right:10px;">首页</a>
             <a href="javascript:gotopage(@(Model.CurrentPageIndex - 1),@Model.TotalPage)" style="margin-right:10px;">前页</a>    
        }
        else
        {
             <a disabled="disabled" style="margin-right:10px;">首页</a>
             <a disabled="disabled" style="margin-right:10px;">前页</a>
        }
        @if (Model.PageFirst > 1)
        {
            <a   href="javascript:gotopage(@(Model.PageFirst - 1),@Model.TotalPage)" style="margin-right:10px;">.&nbsp;.</a>    
        }       
        <script type="text/javascript">
            var totalPage = 0;
            function gotopage(pageIndex, LastPage) {
                totalPage = LastPage;
                document.getElementById('CurrentPageIndex').value = pageIndex;
                document.getElementById('mvcpager_btnchk').click();
            }
            function checkInput(totalPage, isAjax) {
                totalPage = totalPage;
                var pageIndexStr = document.getElementById('CurrentPageIndex').value;
                if (pageIndexStr == "") {
                    alert('请输入页码');

                    document.getElementById('CurrentPageIndex').focus();
                    document.getElementById('CurrentPageIndex').select();
                    return false;
                }
                var pageIndex = parseInt(pageIndexStr);
                var r = new RegExp("^\\s*(\\d+)\\s*$");
                if (r.test(pageIndex)) {
                    if (RegExp.$1 < 1 || RegExp.$1 > totalPage) {
                        alert("页索引超出范围！");
                        document.getElementById('CurrentPageIndex').focus();
                        document.getElementById('CurrentPageIndex').select();
                        return false;
                    }
                    if (isAjax) {
                        getAjaxPageDate(pageIndex);
                        return false;
                    } else {
                        document.getElementById('mvcpager_btn').click();
                        return true;
                    }

                }
                alert("页索引不是有效的数值！");
                document.getElementById('CurrentPageIndex').focus();
                document.getElementById('CurrentPageIndex').select();
                return false;
            }
            </script>
            @for (int i = 0; i < Model.DispPageCount; i++)
            {
                if ((Model.PageFirst + i) <= Model.TotalPage)
                {
                    if (Model.CurrentPageIndex == (Model.PageFirst + i))
                    {
                    <a    href="javascript:gotopage(@(Model.PageFirst + i),@Model.TotalPage)" style="margin-right:10px;color:#FF0000;">@(Model.PageFirst + i)</a> 
                    }
                    else
                    {
                         <a    href="javascript:gotopage(@(Model.PageFirst + i),@Model.TotalPage)" style="margin-right:10px;">@(Model.PageFirst + i)</a> 
                    }
                }
            }         
            @if ((Model.PageFirst + Model.DispPageCount) <= Model.TotalPage)
            {
                <a   href="javascript:gotopage(@(Model.PageFirst + Model.DispPageCount),@Model.TotalPage)" style="margin-right:10px;">.&nbsp;.</a>
            }
            @if (Model.CurrentPageIndex < Model.TotalPage)
            {
                <a href="javascript:gotopage(@(Model.CurrentPageIndex + 1),@Model.TotalPage)" style="margin-right:10px;">后页</a>
                <a href="javascript:gotopage(@Model.TotalPage,@Model.TotalPage)" style="margin-right:10px;">尾页</a>
            }
            else
            {
                 <a disabled="disabled" style="margin-right:10px;">后页</a>
                <a disabled="disabled" style="margin-right:10px;">尾页</a>
            }      
            <span>&nbsp;&nbsp;转到</span>
            <input type="text"  onclick="this.select()" value="@Model.CurrentPageIndex" name="CurrentPageIndex" id="CurrentPageIndex" style="width:30px;" /><span>页</span>
            <input  type="button"  value="Go To" id="mvcpager_btnchk" onclick="return checkInput(@Model.TotalPage,@(Model.IsAjax == true ? 1 : 0))" />
            <input  type="submit" style="display:none"  value="Go" name="mvcpager" id="mvcpager_btn" />
           @* 这样写的作用是防止客户端禁用js或者js出错导致提交。*@
       </div>
}

